﻿using System;
using System.Data;
using System.Configuration;
//using System.Linq;
using System.Xml.Linq;
using System.Windows.Forms;
using Pub;
using ICSharpCode.TextEditor;
using System.IO;
using System.Text;

namespace JCNT.DAL
{
    public class ToolStripMenuItemII : ToolStripMenuItem
    {
        public const int TYP_LAB = 0;
        public const int TYP_TIT = 1;
        public const int TYP_DAT = 2;

        public int typ = TYP_LAB;
        public string RootID;
        public string ID;
        public string sLab;
        public string sTit;
    }

    public class CTreeII
    {
        CSQLServer ado1 = new CSQLServer();
        public Cwp_nlab wp_nlab = new Cwp_nlab();
        public Cwp_note wp_note = new Cwp_note();
        public static string s_Vis = " AND vis = 1 ";

        /// <summary>
        /// 填充树目录及文章
        /// </summary>
        /// <param name="tv1"></param>
        /// <param name="node"></param>
        /// <param name="RootID"></param>
        public void fillTree(TreeView tv1, TreeNodeII node)
        {
            //填充目录
            string strSQL = "Select * From WP_NLab Where 1=1 " + s_Vis + " and RootID='" + node.ID + "' Order By Lab";
            DataSet ds1 = ado1.sel1(strSQL);
            //Pub.bugMsbox("RootID=" + RootID.ToString() + " And ds_count=" + ado1.ds_count.ToString());

            foreach (DataRow dr in ds1.Tables[0].Rows)
            {
                TreeNodeII node1 = new TreeNodeII();
                string Lab = dr["Lab"].ToString();
                string ID = dr["ID"].ToString();
                node1.Text = Lab;
                node1.Tag = ID;
                node1.ID = ID;
                node1.RootID = node.ID;
                node1.sLab = Lab;
                node1.sTit = "";
                node1.ImageIndex = 0;
                node1.SelectedImageIndex = 0;
                node1.typ = TreeNodeII.TYP_LAB;
                node1.sHighlight = dr["Highlight"].ToString();

                fillTree(null, node1);

                node.Nodes.Add(node1);

            }

            //填充文章
            string strSQL2 = "Select ID, Lab, Tit, RootID From WP_Note Where RootID = " + node.ID + " Order By Tit";
            DataSet ds2 = ado1.sel1(strSQL2);
            foreach (DataRow dr2 in ds2.Tables[0].Rows)
            {
                TreeNodeII node2 = new TreeNodeII();
                string Tit = dr2["Tit"].ToString();
                string tID = dr2["ID"].ToString();
                string Lab = dr2["Lab"].ToString();
                node2.Text = Tit;
                node2.Tag = tID;
                node2.ID = tID;
                node2.RootID = node.ID;
                node2.sLab = Lab;
                node2.sTit = Tit;
                node2.ImageIndex = 1;
                node2.SelectedImageIndex = 2;
                node2.typ = TreeNodeII.TYP_TIT;
                node2.sHighlight = node.sHighlight;
                //node1.Nodes.Add(node2);
                //if (node.ID == "0")
                //{
                //    tv1.Nodes.Add(node2);
                //}
                //else
                //{
                node.Nodes.Add(node2);
                //}
            }

            if (node.ID == "0" && tv1 != null)
            {
                tv1.Nodes.Add(node);
            }

        }

        public void fillTree_NextLevel(TreeView tv1, TreeNodeII node)
        {
            try
            {
                string strSQL = "Select * From WP_NLab Where 1=1 " + s_Vis + " and RootID='" + node.ID + "' Order By Lab";
                DataSet ds1 = ado1.sel1(strSQL);
                //Pub.bugMsbox("RootID=" + RootID.ToString() + " And ds_count=" + ado1.ds_count.ToString());

                foreach (DataRow dr in ds1.Tables[0].Rows)
                {
                    TreeNodeII node1 = new TreeNodeII();
                    string Lab = dr["Lab"].ToString();
                    string ID = dr["ID"].ToString();
                    node1.Text = Lab;
                    node1.Tag = ID;
                    node1.ID = ID;
                    node1.RootID = node.ID;
                    node1.sLab = Lab;
                    node1.sTit = "";
                    node1.ImageIndex = 0;
                    node1.SelectedImageIndex = 0;
                    node1.typ = TreeNodeII.TYP_LAB;
                    node1.sHighlight = dr["Highlight"].ToString();

                    //fillTree(null, node1);

                    node.Nodes.Add(node1);

                }

                string strSQL2 = "Select ID, Lab, Tit, RootID From WP_Note Where RootID = " + node.ID + " Order By Tit";
                DataSet ds2 = ado1.sel1(strSQL2);
                foreach (DataRow dr2 in ds2.Tables[0].Rows)
                {
                    TreeNodeII node2 = new TreeNodeII();
                    string Tit = dr2["Tit"].ToString();
                    string tID = dr2["ID"].ToString();
                    string Lab = dr2["Lab"].ToString();
                    node2.Text = Tit;
                    node2.Tag = tID;
                    node2.ID = tID;
                    node2.RootID = node.ID;
                    node2.sLab = Lab;
                    node2.sTit = Tit;
                    node2.ImageIndex = 1;
                    node2.SelectedImageIndex = 2;
                    node2.typ = TreeNodeII.TYP_TIT;
                    node2.sHighlight = node.sHighlight;
                    //node1.Nodes.Add(node2);
                    //if (node.ID == "0")
                    //{
                    //    tv1.Nodes.Add(node2);
                    //}
                    //else
                    //{
                    node.Nodes.Add(node2);
                    //}
                }

                if (node.ID == "0" && tv1 != null)
                {
                    tv1.Nodes.Add(node);
                }

            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }

        }


        public void fillTree2(TreeView tv1, TreeNodeII node)
        {
            try
            {
                string strSQL = "select distinct(left(convert(varchar,setdat,112),4)) as Lab "
                + "from wp_note WHERE 1=1 " + " order by left(convert(varchar,setdat,112),4) desc";
                DataSet ds1 = ado1.sel1(strSQL);
                //Pub.bugMsbox("RootID=" + RootID.ToString() + " And ds_count=" + ado1.ds_count.ToString());

                foreach (DataRow dr in ds1.Tables[0].Rows)
                {
                    TreeNodeII node1 = new TreeNodeII();
                    string Lab = dr["Lab"].ToString();
                    string ID = dr["Lab"].ToString();
                    node1.Text = Lab;
                    node1.Tag = ID;
                    node1.ID = ID;
                    node1.RootID = node.ID;
                    node1.sLab = Lab;
                    node1.sTit = "";
                    node1.ImageIndex = 0;
                    node1.SelectedImageIndex = 0;
                    node1.typ = TreeNodeII.TYP_DAT;

                    string strSQL2 = "select distinct(right(left(convert(varchar,setdat,112),6),2)) as Lab "
                        + "from wp_note WHERE convert(varchar,setdat,112) like '" + node1.Text + "%' "
                        + "order by right(left(convert(varchar,setdat,112),6),2) desc";
                    DataSet ds2 = ado1.sel1(strSQL2);
                    //Pub.bugMsbox("RootID=" + RootID.ToString() + " And ds_count=" + ado1.ds_count.ToString());

                    foreach (DataRow dr2 in ds2.Tables[0].Rows)
                    {
                        TreeNodeII node2 = new TreeNodeII();
                        Lab = dr2["Lab"].ToString();
                        ID = dr2["Lab"].ToString();
                        node2.Text = Lab;
                        node2.Tag = ID;
                        node2.ID = ID;
                        node2.RootID = node.ID;
                        node2.sLab = Lab;
                        node2.sTit = "";
                        node2.ImageIndex = 0;
                        node2.SelectedImageIndex = 0;
                        node2.typ = TreeNodeII.TYP_DAT;

                        #region day
                        string strSQL3 = "select distinct(right(left(convert(varchar,setdat,112),8),2)) AS Lab "
                            + "from wp_note WHERE convert(varchar,setdat,112) like '" + node1.Text + node2.Text + "%' "
                            + "order by right(left(convert(varchar,setdat,112),8),2) desc";
                        DataSet ds3 = ado1.sel1(strSQL3);
                        //Pub.bugMsbox("RootID=" + RootID.ToString() + " And ds_count=" + ado1.ds_count.ToString());

                        foreach (DataRow dr3 in ds3.Tables[0].Rows)
                        {
                            TreeNodeII node3 = new TreeNodeII();
                            Lab = dr3["Lab"].ToString();
                            ID = dr3["Lab"].ToString();
                            node3.Text = Lab;
                            node3.Tag = ID;
                            node3.ID = ID;
                            node3.RootID = node.ID;
                            node3.sLab = Lab;
                            node3.sTit = "";
                            node3.ImageIndex = 0;
                            node3.SelectedImageIndex = 0;
                            node3.typ = TreeNodeII.TYP_DAT;

                            #region 终极节点
                            string strSQL4 = "Select ID, Lab, Tit, RootID From WP_Note "
                                + "Where convert(varchar,setdat,112) like '" + node1.Text + node2.Text + node3.Text + "%'  Order By Tit";
                            DataSet ds4 = ado1.sel1(strSQL4);
                            foreach (DataRow dr4 in ds4.Tables[0].Rows)
                            {
                                TreeNodeII node4 = new TreeNodeII();
                                string Tit = dr4["Tit"].ToString();
                                string tID = dr4["ID"].ToString();
                                Lab = dr4["Lab"].ToString();
                                node4.Text = Tit;
                                node4.Tag = tID;
                                node4.ID = tID;
                                node4.RootID = node.ID;
                                node4.sLab = Lab;
                                node4.sTit = Tit;
                                node4.ImageIndex = 1;
                                node4.SelectedImageIndex = 2;
                                node4.typ = TreeNodeII.TYP_TIT;
                                //node1.Nodes.Add(node2);
                                //if (node.ID == "0")
                                //{
                                //    tv1.Nodes.Add(node2);
                                //}
                                //else
                                //{
                                node3.Nodes.Add(node4);
                                //}
                            }
                            #endregion

                            node2.Nodes.Add(node3);

                        }
                        #endregion

                        node1.Nodes.Add(node2);

                    }

                    node.Nodes.Add(node1);

                }
                if (node.ID == "0")
                {
                    tv1.Nodes.Add(node);
                }
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }

        }

        public void fillMenu(ToolStripMenuItem menu1, ToolStripMenuItemII item)
        {
            string strSQL = "Select * From WP_NLab Where 1=1 " + s_Vis + " and RootID='" + item.ID + "' Order By Lab";
            DataSet ds1 = ado1.sel1(strSQL);
            //Pub.bugMsbox("RootID=" + RootID.ToString() + " And ds_count=" + ado1.ds_count.ToString());

            foreach (DataRow dr in ds1.Tables[0].Rows)
            {
                ToolStripMenuItemII node1 = new ToolStripMenuItemII();
                string Lab = dr["Lab"].ToString();
                string ID = dr["ID"].ToString();
                node1.Text = Lab;
                node1.Tag = ID;
                node1.ID = ID;
                node1.RootID = item.ID;
                node1.sLab = Lab;
                node1.sTit = "";
                node1.ImageIndex = 0;
                node1.typ = TreeNodeII.TYP_LAB;

                fillMenu(null, node1);

                item.DropDownItems.Add(node1);

            }

            if (item.ID == "0")
            {
                menu1.DropDownItems.Add(item);
            }

        }

        public void fillLab(TreeView tv1, TreeNode node, string RootID)
        {
            string strSQL = "Select * From WP_NLab Where 1=1 " + s_Vis + " and RootID='" + RootID + "' Order By Lab";
            DataSet ds1 = ado1.sel1(strSQL);
            //Pub.bugMsbox("RootID=" + RootID.ToString() + " And ds_count=" + ado1.ds_count.ToString());

            foreach (DataRow dr in ds1.Tables[0].Rows)
            {
                TreeNodeII node1 = new TreeNodeII();
                string Lab = dr["Lab"].ToString();
                string ID = dr["ID"].ToString();
                node1.Text = Lab;
                node1.Tag = ID;
                node1.ImageIndex = 0;
                node1.SelectedImageIndex = 0;
                node1.typ = TreeNodeII.TYP_LAB;

                fillLab(null, node1, ID);


                //if (RootID == "0")
                //{
                node.Nodes.Add(node1);
                //}
                //else
                //{
                //    node.Nodes.Add(node1);
                //}
            }
            if (RootID == "0")
                tv1.Nodes.Add(node);
        }

        public void findNode(TreeView tView1, String ID)
        {
            if (ID != "")
            {
                foreach (TreeNode node1 in tView1.Nodes)
                {
                    //CPub.Send(node1.Text + "," + node1.Tag.ToString() + "," + ID);
                    if (Convert.ToString(node1.Tag) == ID)
                    {

                        TreeNode node2 = node1;
                        while (node2.Parent != null)
                        {
                            //if (((TreeNodeII)node2).typ == 1)
                            node2.Parent.Expand();
                            //node2.Parent.ImageUrl = "images/jian.jpg";
                            node2 = (TreeNode)node2.Parent;

                        }
                        node1.Expand();
                        //node1.ImageUrl = "images/jian.jpg";
                    }
                    else
                    {
                        findNode(node1, ID);
                    }
                }

            }

        }

        public void findNode(TreeNode nodes, string ID)
        {
            foreach (TreeNode node1 in nodes.Nodes)
            {

                if (Convert.ToString(node1.Tag) == ID)
                {
                    //CPub.Send(ID);
                    TreeNode node2 = node1;
                    while (node2.Parent != null)
                    {
                        //if (((TreeNodeII)node2).typ == 1)
                        node2.Parent.Expand();
                        //node2.Parent.ImageUrl = "images/jian.jpg";
                        node2 = (TreeNode)node2.Parent;
                    }
                    node1.Expand();
                    //node1.ImageUrl = "images/jian.jpg";
                }
                else
                {
                    findNode(node1, ID);
                }
            }
        }

        public Cwp_note get_wp_note(string ID)
        {
            string s_sql = "select * from wp_note where id = " + ID;
            DataSet ds1 = ado1.sel1(s_sql);
            if (CPub.dsIsNull(ds1)) return null;
            wp_note.ID = ds1.Tables[0].Rows[0]["ID"].ToString();
            wp_note.Tit = ds1.Tables[0].Rows[0]["Tit"].ToString();
            wp_note.Con = ds1.Tables[0].Rows[0]["Con"].ToString();
            wp_note.Lab = ds1.Tables[0].Rows[0]["Lab"].ToString();
            wp_note.SetDat = ds1.Tables[0].Rows[0]["SetDat"].ToString();
            wp_note.EdiDat = ds1.Tables[0].Rows[0]["EdiDat"].ToString();
            wp_note.Oth = ds1.Tables[0].Rows[0]["Oth"].ToString();
            wp_note.Pas1 = ds1.Tables[0].Rows[0]["Pas1"].ToString();
            wp_note.pas2 = ds1.Tables[0].Rows[0]["pas2"].ToString();
            wp_note.pas3 = ds1.Tables[0].Rows[0]["pas3"].ToString();
            wp_note.pas4 = ds1.Tables[0].Rows[0]["pas4"].ToString();
            wp_note.RootID = ds1.Tables[0].Rows[0]["RootID"].ToString();
            if (ds1.Tables[0].Rows[0]["Dat"].ToString() != "")
                wp_note.Dat = (byte[])ds1.Tables[0].Rows[0]["Dat"];
            else
                wp_note.Dat = null;

            return wp_note;
        }

        public Cwp_nlab get_wp_nlab(string ID)
        {
            string s_sql = "select * from wp_nlab where id = " + ID;
            DataSet ds1 = ado1.sel1(s_sql);
            if (CPub.dsIsNull(ds1)) return null;
            wp_nlab.ID = ds1.Tables[0].Rows[0]["ID"].ToString();
            wp_nlab.Lab = ds1.Tables[0].Rows[0]["Lab"].ToString();
            wp_nlab.Vis = ds1.Tables[0].Rows[0]["Vis"].ToString();
            wp_nlab.RootID = ds1.Tables[0].Rows[0]["RootID"].ToString();


            return wp_nlab;
        }

        public void fillLab(ComboBox cbox1)
        {
            cbox1.Items.Clear();
            cbox1.Items.Add(new MyComboBoxItem(@"\", "0"));
            string strSQL = "Select * From WP_NLab Where 1 = 1 " + s_Vis + " Order By Lab";
            DataSet ds1 = ado1.sel1(strSQL);

            if (ado1.ds_count == 0) return;
            foreach (DataRow dr in ds1.Tables[0].Rows)
            {
                string nam = dr["Lab"].ToString();
                string val = dr["ID"].ToString();
                MyComboBoxItem item1 = new MyComboBoxItem(nam, val);
                cbox1.Items.Add(item1);
            }
        }

        public void fillTit(ListBox lbox1, string ID)
        {
            lbox1.Items.Clear();
            string strSQL = "Select ID,Tit,Lab,RootID From WP_note Where RootID=" + ID + " Order By Tit";
            DataSet ds1 = ado1.sel1(strSQL);
            if (ado1.ds_count == 0) return;
            foreach (DataRow dr in ds1.Tables[0].Rows)
            {
                string nam = dr["Tit"].ToString();
                string val = dr["ID"].ToString();
                MyComboBoxItem item1 = new MyComboBoxItem(nam, val);
                lbox1.Items.Add(item1);
            }
        }

        public void fillTitII(ListBox lbox1, string s1, string sID)
        {
            string[] s_key = s1.Split(' ');
            string s_Where1 = "";
            string s_Where2 = "";
            string s_Where3 = sID == "" ? "" : " AND A.RootID=" + sID;
            foreach (string s_tem in s_key)
            {
                s_Where1 += " AND A.Tit like '%" + s_tem + "%'";
                s_Where2 += " AND A.Con like '%" + s_tem + "%'";
            }

            lbox1.Items.Clear();
            string strSQL = "Select A.ID,A.Tit,B.Lab,B.RootID From WP_note A "
                + "Left Join wp_NLab B on A.RootID=B.ID "
                + "Where ((1=1 " + s_Where1 + ") OR (1=1 " + s_Where2 + ")) " + s_Where3
                + s_Vis + " Order By Tit";
            DataSet ds1 = ado1.sel1(strSQL);
            if (ado1.ds_count == 0) return;
            foreach (DataRow dr in ds1.Tables[0].Rows)
            {
                string nam = dr["Tit"].ToString();
                string val = dr["ID"].ToString();
                MyComboBoxItem item1 = new MyComboBoxItem(nam, val);
                lbox1.Items.Add(item1);
            }
        }

        public string newLabID()
        {
            string strSQL = "select Max(ID) + 1 as newID From wp_nlab";
            ado1.sel1(strSQL);
            if (ado1.ds_count == 0) return "1";
            else return ado1.ds.Tables[0].Rows[0]["newID"].ToString();
        }

        public void labMov(int ID, int RootID)
        {
            string strSQL = "UPDATE wp_nlab SET RootID=" + RootID + " WHERE ID<>" + RootID + " AND ID=" + ID;
            ado1.cmd1(strSQL);
        }

        public void labAdd(Cwp_nlab wp_nlab)
        {
            string strSQL = "Insert Into WP_NLab Values("
                + " " + wp_nlab.ID + " , "
                + "'" + wp_nlab.Lab + "', "
                + "'" + wp_nlab.Vis + "', "
                + "'" + wp_nlab.RootID + "'  "
                + ")";
            ado1.cmd1(strSQL);
        }

        public void labEdt(Cwp_nlab wp_nlab)
        {
            string strSQL = "Update WP_NLab Set  "
                + "Lab    ='" + wp_nlab.Lab + "', "
                + "Vis    ='" + wp_nlab.Vis + "', "
                + "RootID ='" + wp_nlab.RootID + "'  "
                + "Where ID=" + wp_nlab.ID;
            ado1.cmd1(strSQL);
        }

        public void labDel(string ID)
        {
            CDebug.EnterMethod("删除标签");

            try
            {
                string strSQL = "Select * from WP_NLab Where RootID=" + ID;
                DataSet ds1 = ado1.sel1(strSQL);
                CDebug.Send(strSQL + "\n返回结果个数:" + ado1.ds_count);
                int n = ado1.ds_count;
                if (n > 0)
                {
                    foreach (DataRow dr1 in ds1.Tables[0].Rows)
                    {
                        labDel(dr1["ID"].ToString());
                    }
                }

                strSQL = "Delete From WP_note Where RootID=" + ID;
                ado1.cmd1(strSQL);
                CDebug.Send(strSQL);

                strSQL = "Delete From WP_NLab Where ID=" + ID;
                ado1.cmd1(strSQL);
                CDebug.Send(strSQL);
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }

            CDebug.ExitMethod("删除标签");
        }

        public void labDel(TreeNodeII node1)
        {
            CDebug.EnterMethod("删除目录 [" + node1.Text + "]");

            string strSQL = "Select * from WP_NLab Where RootID=" + node1.ID;
            DataSet ds1 = ado1.sel1(strSQL);
            CDebug.Send(strSQL + "\n--返回结果个数: " + ado1.ds_count);
            int n = ado1.ds_count;
            if (n > 0)
            {
                foreach (DataRow dr1 in ds1.Tables[0].Rows)
                {
                    TreeNodeII node2 = new TreeNodeII();
                    node2.ID = dr1["ID"].ToString();
                    node2.RootID = dr1["rootID"].ToString();
                    labDel(node2);
                }
            }
            strSQL = "Delete From WP_note Where RootID=" + node1.ID;
            ado1.cmd1(strSQL);
            CDebug.Send(strSQL);

            strSQL = "Delete From WP_NLab Where ID=" + node1.ID;
            ado1.cmd1(strSQL);
            CDebug.Send(strSQL);

            CDebug.ExitMethod("删除目录 [" + node1.Text + "]");
        }


        public void labAdd(TreeNodeII wp_nlab)
        {
            CDebug.EnterMethod("添加新标签");
            string strSQL = "Insert Into WP_NLab (ID, Lab, Vis, RootID, Highlight)Values("
                + " " + wp_nlab.ID + " , "
                + "'" + wp_nlab.sLab + "', "
                + "'" + wp_nlab.sVis + "', "
                + "'" + wp_nlab.RootID + "',  "
                + "'" + wp_nlab.sHighlight + "'  "
                + ")";
            CDebug.Send(strSQL);
            ado1.cmd1(strSQL);
            CDebug.ExitMethod("添加新标签");
        }

        public string labAdd(string sRootID, string sLab)
        {
            TreeNodeII node2 = new TreeNodeII();
            node2.sLab = sLab;
            node2.sVis = "1";
            node2.Text = sLab;
            string sID = newLabID();
            node2.ID = sID;
            node2.RootID = sRootID;
            labAdd(node2);
            return sID;
        }

        public void labEdt(TreeNodeII wp_nlab)
        {
            CDebug.EnterMethod("修改标签");
            string strSQL = "Update WP_NLab Set  "
                + "Lab    ='" + wp_nlab.sLab + "', "
                + "Vis    ='" + wp_nlab.sVis + "', "
                + "RootID ='" + wp_nlab.RootID + "', "
                + "Highlight ='" + wp_nlab.sHighlight + "'  "
                + "Where ID=" + wp_nlab.ID;
            CDebug.Send(strSQL);
            ado1.cmd1(strSQL);
            CDebug.ExitMethod("修改标签");
        }



        public Boolean LabIsNull(string sID)
        {
            string strSQL = "select ID From wp_nlab WHERE ID=" + sID;
            ado1.sel1(strSQL);
            if (ado1.ds_count == 0) return true;
            else return false;
        }

        public string LabID(string sRootID, string sLab)
        {
            string strSQL = "select ID From wp_nlab WHERE RootID=" + sRootID + " AND Lab='" + sLab + "'";
            ado1.sel1(strSQL);
            if (ado1.ds_count == 0) return "";
            else return ado1.ds.Tables[0].Rows[0]["ID"].ToString();
        }

        public string newNodeID()
        {
            string strSQL = "select Max(ID) + 1 as newID From wp_note";
            ado1.sel1(strSQL);
            if (ado1.ds_count == 0) return "1";
            else return ado1.ds.Tables[0].Rows[0]["newID"].ToString();
        }

        public void noteMov(int ID, int RootID)
        {
            string strSQL = "UPDATE wp_note SET RootID=" + RootID + " WHERE ID=" + ID;
            ado1.cmd1(strSQL);
        }

        public void noteAdd(Cwp_note wp_note)
        {
            string strSQL = "Insert Into WP_Note("
              + "ID      , "  // INTEGER NOT NULL,
              + "Tit     , "  // CHAR(50) NOT NULL,
              + "Con     , "  // TEXT,
              + "Lab     , "  // CHAR(50) NOT NULL,
              + "SetDat  , "  // DATETIME,
              + "Oth     , "  // CHAR(50),
              + "RootID    "  // CHAR(50));
              + ") Values( "
              + " " + wp_note.ID + "  , "
              + "'" + wp_note.Tit + "', "
              + "'" + wp_note.ConII + "', "
              + "'" + wp_note.Lab + "', "
              + "'" + wp_note.SetDat + "', "
              + "'" + wp_note.Oth + "', "
              + "'" + wp_note.RootID + "'  "
              + ")";
            ado1.cmd1(strSQL);
        }

        public void noteAdd(string sRootID, string sLab, string sCon, string sTit, string sOth)
        {
            wp_note.Lab = sLab;
            wp_note.Tit = sTit;
            wp_note.Con = sCon;
            wp_note.Oth = sOth;
            wp_note.RootID = sRootID;
            wp_note.SetDat = CPub.sNow();
            string sID = newNodeID();
            wp_note.ID = sID;
            noteAdd(wp_note);
        }

        /// <summary>
        /// 保存文本
        /// </summary>
        /// <param name="wp_note"></param>
        public void noteEdt(Cwp_note wp_note)
        {
            string strSQL = "Update WP_Note Set "
              + "Tit     = " + "'" + wp_note.Tit + "', "
              + "Con     = " + "'" + wp_note.ConII + "', "
              + "Lab     = " + "'" + wp_note.Lab + "', "
              + "SetDat  = " + "'" + wp_note.SetDat + "', "
              + "Oth     = " + "'" + wp_note.Oth + "', "
              + "RootID  = " + "'" + wp_note.RootID + "'  "
              + "Where ID= " + wp_note.ID;
            ado1.cmd1(strSQL);
        }

        public void noteDel(string ID)
        {
            ado1.cmd1("Delete From WP_Note Where ID=" + ID);
        }

        /// <summary>
        /// 保存写字板格式
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="tbox"></param>
        public void conEdt(string ID, RichTextBox tbox)
        {
            string strSQL = "Where ID=" + ID;
            string tab = "wp_note";
            string col = "Dat";
            ado1.save_RchText(tab, strSQL, col, tbox);
        }

        public void conEdt(string ID, TextEditorControl tbox)
        {
            string strSQL = "Where ID=" + ID;
            string tab = "wp_note";
            string col = "Dat";
            ado1.save_RchText(tab, strSQL, col, tbox);
        }


        public void ImportFile(string sRootID, string sPath, string sFileName)
        {

            string[] sPaths = sPath.Split('\\');
            string sLab = "";
            string sRootID_Tem = sRootID;
            //检查目录是否存在，不存在则创建
            for (int i = 0; i < sPaths.Length - 1; i++)
            {
                if (sPaths[i] != string.Empty)
                {
                    sLab = sPaths[i];
                    string s1 = LabID(sRootID_Tem, sLab);
                    if (s1 == string.Empty)
                        sRootID_Tem = labAdd(sRootID_Tem, sLab);
                    else
                        sRootID_Tem = s1;
                }
            }

            //保存文件内容
            string sOth = "w_p_";
            string sTit = sPaths[sPaths.Length - 1];
            string sCon = File.ReadAllText(sFileName, Encoding.Default);

            noteAdd(sRootID_Tem, sLab, sCon, sTit, sOth);
        }
    }

    public class TreeNodeII : TreeNode
    {
        public const int TYP_LAB = 0;
        public const int TYP_TIT = 1;
        public const int TYP_DAT = 2;

        //public Cwp_note wp_note;
        public int typ = TYP_LAB;
        public string RootID;
        public string ID;
        public string sLab;
        public string sTit;
        public string sHighlight;
        public string sVis;
    }


}
